package gov.nist.healthcare.testframework.client;

import gov.nist.healthcare.configuration.testframework.TestFrameworkDocument;
import gov.nist.healthcare.configuration.testframework.testagent.TestAgentConfigurationDocument;
import gov.nist.healthcare.core.MalformedMessageException;
import gov.nist.healthcare.core.message.v2.er7.Er7Message;
import gov.nist.healthcare.testframework.Environment;
import gov.nist.healthcare.testframework.TestFramework;
import gov.nist.healthcare.testframework.application.generic.GenericInitiatorTestAgent;
import java.io.IOException;
import org.apache.xmlbeans.XmlException;

public class TestFrameworkInitiator {

    /**
     * @param args
     * @throws IOException
     * @throws XmlException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws ClassNotFoundException
     * @throws MalformedMessageException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws XmlException, IOException,
            ClassNotFoundException, InstantiationException,
            IllegalAccessException, MalformedMessageException,
            InterruptedException {
        TestFrameworkDocument testFrameworkDocument = TestFrameworkDocument.Factory.parse(TestFrameworkReceiver.class.getResource("/configuration/TestFrameworkInitiatorConfiguration.xml"));
        TestFramework tf = TestFramework.getInstance();
        tf.init(testFrameworkDocument);
        // Add a generic initiator test agent
        TestAgentConfigurationDocument testAgentDocument = TestAgentConfigurationDocument.Factory.parse(TestFrameworkReceiver.class.getResource("/configuration/TestAgentInitiatorConfiguration.xml"));
        GenericInitiatorTestAgent generic = (GenericInitiatorTestAgent) Environment.getInstance().addTestAgent(
                testAgentDocument);
        String message = "MSH|^~\\&|NIST_SENDER|NIST|NIST_RECEIVER|NIST|20090810141748||ADT^A04^ADT_A01|Flame-990001|P|2.3.1\n"
                + "EVN|A04|20090810\n"
                + "PID|||100^^^domain1&1.2.3.4.5.1000&ISO^PI||MOORE^CHIP|Barnes|19840711|M|||^^Montreal^^||||||||153-12-5100\n"
                + "PV1||V\n";
        Er7Message er7 = new Er7Message(message);
        generic.send(er7, false);
        Thread.sleep(30000);
        tf.terminate();
    }
}
